<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('修改工器具使用记录')"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-history-edit" th:object="${tZhgdDeviceToolsStorageHistory}">
        <input name="id" id="id" th:field="*{id}" type="hidden">
        <input id="toolIdZ" th:value="*{toolId}" type="hidden">

        <div class="col-xs-12">
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">RFID：</label>
                <div class="col-sm-8">
                    <input name="rfid" th:field="*{rfid}" class="form-control" type="text" required>
                </div>
            </div>
        </div>

        <div class="col-xs-12">
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">工器具类型：</label>
                <div class="col-sm-8">
                    <select name="toolTypeCode" id="toolTypeCode" class="form-control"
                            th:with="type=${@dict.getType('tools_type')}" onchange="changeToolType()" required>
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"
                                th:field="*{toolTypeCode}"></option>
                    </select>
                </div>
            </div>
        </div>

        <div class="col-xs-12">
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">工器具名称：</label>
                <div class="col-sm-8">
                    <select name="toolId" id="toolId" class="form-control" required>
                    </select>
                </div>
            </div>
        </div>

    </form>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var cishu = 8
    window.onload = function () {
        changeToolType();
    };
    var prefix = ctx + "system/history";
    $("#form-history-edit").validate({
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/edit", $('#form-history-edit').serialize());
        }
    }

    function changeToolType() {
        var checkValue = $("#toolTypeCode").val();  //获取Select选择的Value
        // 获取select元素
        var select = document.getElementById('toolId');
        select.innerHTML = '';//清空

        $.ajax({
            type: "post",
            url: prefix + "/findDropDownList",
            data: {
                "toolTypeCode": checkValue
            },
            success: function (data) {
                // 动态添加选项
                data.data.forEach(function (item) {
                    var option = document.createElement('option');
                    option.value = item.id;
                    option.text = item.toolName;
                    select.appendChild(option);

                    if (cishu <= 1) {
                        cishu++;
                        select.value = $('#toolIdZ').val(); // 设置默认选中项
                    }

                });
            }
        });
    }

</script>
</body>
</html>